﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Dictionary.EmployTest;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.FormBase;
using WindowsForms.AOnline.WindowsForm.Resources;

namespace WindowsForms.AOnline.WindowsForm.FormDictionary
{
    public partial class FrmXtraEmployDetail : FrmXtraBaseCategoryDetail, IEmployTestView  
    {
        private readonly EmployTestPresenter _employTestPresenter; 

        public FrmXtraEmployDetail()
        {
            InitializeComponent();
            _employTestPresenter = new EmployTestPresenter(this);
        }
        /// <summary>
        /// Initializes the data.
        /// </summary>
        protected override void InitData()
        {
            if (KeyValue != null)
                _employTestPresenter.Display(KeyValue);
            //else
            //    chkIsActive.Checked = true;
        }

        /// <summary>
        /// Valids the data.
        /// </summary>
        /// <returns></returns> 
        protected override bool ValidData()
        {
            if (string.IsNullOrEmpty(EmployName))
            {
                XtraMessageBox.Show("Chưa nhập tên nhân viên",
                              ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtName.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(Salary.ToString()))
            {
                XtraMessageBox.Show("Chưa nhập lương",
                                ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtSalary.Focus();
                return false;
            }
            return true;
        }

        /// <summary>
        /// Saves the data.
        /// </summary>
        /// <returns></returns>
        protected override string SaveData()
        {
            return _employTestPresenter.Save();
        }

        /// <summary>
        /// Focuses the control.
        /// </summary>
        protected override void InitControls()
        {
            txtName.Focus();
        }

        public int EmployId
        {  get ;
            set;
        }

        public decimal Salary
        {
            get
            {
                return decimal.Parse(txtSalary.Text);
            }
            set
            {
                txtSalary.Text = value.ToString();
            }
        }

        public int DepartmentId
        {
            get
            {
                return int.Parse(txtDepartment.Text);
            }
            set
            {
                txtDepartment.Text = value.ToString();
            }
        }

        public string EmployName
        {
            get
            {
                return txtName.Text;
            }
            set
            {
                txtName.Text = value;
            }
        }
    }
}
